home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / macabuse / inc / lisp.hpp < prev    next >
C/C++ Source or Header  |  1997-05-20  |  6KB  |  219 lines

  1. #ifndef __LISP_HPP_
  2. #define __LISP_HPP_
  3.  
  4. #include "lisp_opt.hpp"
  5.  
  6. //#define L_PROFILE 1 
  7. #ifdef L_PROFILE
  8. #include "timing.hpp"
  9. #endif
  10.  
  11. #define Cell void
  12. #define MAX_LISP_TOKEN_LEN 200
  13. enum { PERM_SPACE,
  14.        TMP_SPACE,
  15.        USER_SPACE,
  16.        GC_SPACE };
  17. #define CAR(x) ((cons_cell *)x)->car
  18. #define CDR(x) ((cons_cell *)x)->cdr
  19.  
  20.  
  21. #define FIXED_TRIG_SIZE 360               // 360 degrees stored in table
  22. extern long sin_table[FIXED_TRIG_SIZE];   // this should be filled in by external module
  23. #define TBS 1662                          // atan table granularity
  24. extern unsigned short atan_table[TBS];
  25. #define NILP(x) (x==NULL)
  26. #define DEFINEDP(x) (x!=l_undefined)
  27. class bFILE;
  28. extern int current_space;
  29. extern bFILE *current_print_file;
  30.  
  31.  
  32. enum { L_BAD_CELL,   // error catching type
  33.        L_CONS_CELL, L_NUMBER, L_SYMBOL,     L_SYS_FUNCTION, L_USER_FUNCTION, 
  34.        L_STRING, L_CHARACTER, L_C_FUNCTION, L_C_BOOL,       L_L_FUNCTION, L_POINTER,
  35.        L_OBJECT_VAR, L_1D_ARRAY,
  36.        L_FIXED_POINT, L_COLLECTED_OBJECT };
  37.  
  38. typedef long ltype;    // make sure structures aren't packed differently on various compiler
  39.                        // and sure that word, etc are word alligned
  40.  
  41. struct lisp_object_var
  42. {  
  43.   ltype type;
  44.   long number;  
  45. } ;
  46.  
  47. struct cons_cell
  48. {
  49.   ltype type;
  50.   void *cdr,*car;
  51. } ;
  52.  
  53. struct lisp_number
  54. {
  55.   ltype type;
  56.   long num;
  57. } ;
  58.  
  59. struct lisp_collected_object
  60. {
  61.   ltype type;
  62.   void *new_reference;
  63. } ;
  64.  
  65. struct lisp_symbol
  66. {
  67.   ltype type;
  68. #ifdef L_PROFILE
  69.   float time_taken;
  70. #endif
  71.   void *value, *function, *name;
  72.   lisp_symbol *left,*right;       // tree structure
  73. } ;
  74.  
  75. struct lisp_sys_function
  76. {
  77.   ltype type;
  78.   short min_args,max_args,fun_number;
  79.   long (*fun)(void *);
  80.   
  81. } ;
  82.  
  83. struct lisp_user_function
  84. {
  85.   ltype type;
  86. #ifndef NO_LIBS
  87.   long alist,blist;      // id for cached blocks
  88. #else
  89.   void *arg_list,*block_list;
  90. #endif
  91. } ;
  92.  
  93. struct lisp_1d_array
  94. {
  95.   ltype type;
  96.   unsigned short size; 
  97.   // size * sizeof (void *) follows1
  98. } ;
  99.  
  100. struct lisp_string
  101. {
  102.   ltype type; 
  103. } ;
  104.  
  105. struct lisp_character
  106. {
  107.   ltype type;
  108.   short pad;
  109.   unsigned short ch;
  110. } ;
  111.  
  112. struct lisp_pointer
  113. {
  114.   ltype type; 
  115.   void *addr;
  116. } ;
  117.  
  118.  
  119. struct lisp_fixed_point
  120. {
  121.   ltype type;
  122.   long x;
  123. } ;
  124.  
  125.  
  126. void perm_space();
  127. void tmp_space();
  128. void use_user_space(void *addr, long size);
  129. #define item_type(c) ((c) ? *((ltype *)c) : (ltype)L_CONS_CELL)
  130. void *lget_array_element(void *a, long x);
  131. void *lpointer_value(void *lpointer);
  132. long lnumber_value(void *lnumber);
  133. char *lstring_value(void *lstring);
  134. unsigned short lcharacter_value(void *c);
  135. long lfixed_point_value(void *c);
  136. void *lisp_atom(void *i);
  137. void *lcdr(void *c);
  138. void *lcar(void *c);
  139. void *lisp_eq(void *n1, void *n2);
  140. void *lisp_equal(void *n1, void *n2);
  141. lisp_symbol *find_symbol(char *name);
  142. long list_length(void *i);
  143. void lprint(void *i);
  144. void *eval(void *prog);
  145. void *eval_block(void *list);
  146. void *eval_function(lisp_symbol *sym, void *arg_list);
  147. void *eval_user_fun(lisp_symbol *sym, void *arg_list);
  148. void *compile(char *&s);
  149. void *symbol_value(void *symbol);
  150. void *symbol_function(void *symbol);
  151. void *set_symbol_number(void *symbol, long num);
  152. void *set_symbol_value(void *symbol, void *value);
  153. void *symbol_name(void *symbol);
  154. void *assoc(void *item, void *list);
  155. void resize_tmp(int new_size);
  156. void resize_perm(int new_size);
  157. lisp_symbol *make_find_symbol(char *name);
  158.  
  159. void push_onto_list(void *object, void *&list);
  160. lisp_symbol *add_c_object(void *symbol, short number);
  161. lisp_symbol *add_c_function(char *name, short min_args, short max_args, long (*fun)(void *));
  162. lisp_symbol *add_c_bool_fun(char *name, short min_args, short max_args, long (*fun)(void *));
  163. lisp_symbol *add_lisp_function(char *name, short min_args, short max_args, short number);
  164. int read_ltoken(char *&s, char *buffer);
  165. cons_cell *new_cons_cell();
  166. void print_trace_stack(int max_levels);
  167.  
  168.  
  169. lisp_number *new_lisp_number(long num);
  170. lisp_pointer *new_lisp_pointer(void *addr);
  171. lisp_character *new_lisp_character(unsigned short ch);
  172. lisp_string *new_lisp_string(char *string);
  173. lisp_string *new_lisp_string(char *string, int length);
  174. lisp_string *new_lisp_string(long length);
  175. lisp_fixed_point *new_lisp_fixed_point(long x);
  176. lisp_object_var *new_lisp_object_var(short number);
  177. lisp_1d_array   *new_lisp_1d_array(unsigned short size, void *rest);
  178. lisp_sys_function *new_lisp_sys_function(int min_args, int max_args, int fun_number);
  179. lisp_sys_function *new_lisp_c_function(int min_args, int max_args, long (*fun)(void *));
  180. lisp_sys_function *new_lisp_c_bool(int min_args, int max_args, long (*fun)(void *));
  181.  
  182. #ifdef NO_LIBS
  183. lisp_user_function *new_lisp_user_function(void *arg_list, void *block_list);
  184. #else
  185. lisp_user_function *new_lisp_user_function(long arg_list, long block_list);
  186. #endif
  187.  
  188. lisp_sys_function *new_user_lisp_function(int min_args, int max_args, int fun_number);
  189.  
  190. int end_of_program(char *s);
  191. void clear_tmp();
  192. void lisp_init(long perm_size, long tmp_size);
  193. void lisp_uninit();
  194. extern lisp_symbol *lsym_root;
  195.  
  196. extern char *space[4],*free_space[4];
  197. extern int space_size[4];
  198. void *nth(int num, void *list);
  199. long lisp_atan2(long dy, long dx);
  200. long lisp_sin(long x);
  201. long lisp_cos(long x);
  202. void restore_heap(void *val, int heap);
  203. void *mark_heap(int heap);
  204.  
  205. extern "C" {
  206. void lbreak(const char *format, ...);
  207. } ;
  208.  
  209. extern void clisp_init();                      // external initalizer call by lisp_init()
  210. extern void *l_caller(long number, void *arg);  // exten lisp function switches on number
  211.  
  212. extern void *l_obj_get(long number);  // exten lisp function switches on number
  213. extern void l_obj_set(long number, void *arg);  // exten lisp function switches on number
  214. extern void l_obj_print(long number);  // exten lisp function switches on number
  215.  
  216.  
  217.  
  218. #endif
  219.